/**
 * @Description: vue config文件
 * @Author: jiangang
 * @Date: 2022-03-07
 * @LastEditTime: 10:01:02
 */

import axios from 'axios';
import {getStorage} from '@/utils/storage';
import {responseError, responseResolve, apiBase} from './config';
const config = {
  withCredentials: false,
  timeout: 1000 * 60 * 5,
  headers: {
    // 'Content-Type': 'application/x-www-form-urlencoded',
    'X-Requested-With': 'XMLHttpRequest',
    Accept: 'application/json',
    'X-Content-Type-Options': 'nosniff',
    'Content-Security-PoliCy': 'default-src \'self\' 192.168.82.116:8088 \'unsafe-inline\' \'unsafe-eval\' blob: data;',
  },
}

let source = axios.CancelToken.source()

const request = axios.create({
  baseURL: apiBase,
  ...config,
  cancelToken: source.token
});
request.mySource = source
request.interceptors.request.use(
  config => {
    const token = getStorage('token')
    if (token) {
      config.headers.token = token;
    }
    return config;
  },
  err => Promise.reject(err),
);
request.interceptors.response.use(
  responseResolve,
  responseError,
);
export default request;
